package org.wzq.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.wzq.data.SpittleRepository;

/**
 * author:wzq
 * project:spring_in_action
 * date:16-5-9
 */
@Controller
@RequestMapping("/spittles")
public class SpittleController {

    private SpittleRepository spittleRepository;

    @Autowired
    public SpittleController(SpittleRepository spittleRepository) {
        System.out.println("SpittleController setup");
        this.spittleRepository = spittleRepository;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String modelAndView(ModelMap model) {
        model.addAttribute("spittleList", spittleRepository.findSpittles(20));
        return "spittles";
    }
}
